// Ofri Keidar 302933981 group 05

package view.useBeans;

/**
 * Bean class holding employee's data
 */
public class EmployeeData {

	// employee's details
	String number;
	String name;
	String userName;
	String permission;
	
	// setters
	
	/**
	 * Sets employee's number
	 * @param number- number to set
	 */
	public void setNumber(String number) { this.number = number; }
	
	/**
	 * Sets employee's name
	 * @param name- name to set
	 */
	public void setName(String name) { this.name = name; }
	
	/**
	 * Sets employee's user-name
	 * @param user-name to set
	 */
	public void setUserName(String userName) { this.userName = userName; }
	
	/**
	 * Sets employee's permission
	 * @param permission- to set
	 */
	public void setPermission(String permission) {	this.permission = permission; }

	/**
	 * Returns employee's number
	 * @return number attribute
	 */
	public String getNumber() { return number; }

	/**
	 * Returns employee's name
	 * @return name attribute
	 */
	public String getName() { return name; }

	/**
	 * Returns employee' user-name
	 * @return user-name attribute
	 */
	public String getUserName() { return userName; }

	/**
	 * Returns employee's permission
	 * @return permission attribute
	 */
	public String getPermission() { return permission; }
	
	// utilities
	
	/**
	 * Checks if data had been already set.
	 * Data is set if members are not null nor empty strings
	 * @return True if data is set, False if not
	 */
	public boolean isDataSet() {
		
		// validate number
		boolean isNumberSet = true;
		if (number == null) { isNumberSet = false; }
		else if (number.equals("")) { isNumberSet = false; }
		
		// validate name
		boolean isNameSet = true;
		if (name == null) { isNameSet = false; }
		else if (name.equals("")) { isNameSet = false; }
		
		// validate user-name
		boolean isUserNameSet = true;
		if (userName == null) { isUserNameSet = false; }
		else if (userName.equals("")) { isUserNameSet = false; }

		// validate permission
		boolean isPermissionSet = true;
		if (permission == null) { isPermissionSet = false; }
		else if (permission.equals("")) { isPermissionSet = false; }
		
		// check if parameters are set
		return isNumberSet && isNameSet && isUserNameSet && isPermissionSet;
	}
	
	/**
	 * Returns employee number's numeric value.
	 * If data is not set or number string cannot 
	 * be parsed to a positive integer, returns null
	 * @return employee number's numeric value
	 */
	public Integer getNumberValue() {
		
		// check if received a number
		if (number == null) { return null; }
		if (number.equals("")) { return null; }
		
		// try parsing employee number
		try {
			
			// parse numeric value
			Integer parsedVal = Integer.parseInt(number);
			
			// check success
			if (parsedVal == null) { return null; }
			
			// parsed value is a number, check if positive
			if (parsedVal <= 0) {
				
				// customer number cannot be positive
				return null; 
			}			
			
			// parsed value is a positive integer
			return parsedVal;
			
		} catch (NumberFormatException e) {
			
			// content is not numeric
			return null;
		}
	}
}